package com.neuedu.his.dao;

import com.neuedu.his.entity.Register;
import com.neuedu.his.entity.Register;
import com.neuedu.his.framework.BaseDao;
import com.neuedu.util.JDBCUtil;

import java.util.List;

/**
 * 项目：      his
 * 类名:       RoleDao
 * 创建时间：  2020/12/23  8:43
 * 描述 :     用户数据访问层
 * 作者 :     张金山
 * QQ :     314649444
 * Site:      https://jshand.gitee.io
 */
public class RegisterDao implements BaseDao<Register> {


    @Override
    public List<Register> selectList(String sql, Object... args) {
        return JDBCUtil.executeQuery(sql, Register.class, args);
    }

    @Override
    public Register selectById(Integer id) {
        String sql = " select * from register where id = ?";
        return JDBCUtil.getOne(sql, Register.class, id);
    }

    @Override
    public boolean update(Register register) {

        StringBuffer sql = new StringBuffer();
        sql.append(" UPDATE 						");
        sql.append("   register                     ");
        sql.append(" SET                            ");
        sql.append("    name  				= ?,    ");
        sql.append("    gender 				= ?,    ");
        sql.append("    idno 				= ?,    ");
        sql.append("    birthday 			= ?,    ");
        sql.append("    age 					= ?,");
        sql.append("    address 				= ?,");
        sql.append("    regsit_level_id 		= ?,");
        sql.append("    dept_id 				= ?,");
        sql.append("    doctor_id 			= ?,    ");
        sql.append("    book 				= ?,    ");
        sql.append("    visittime 			= ?,    ");
        sql.append("    fee 					= ?,");
        sql.append("    readme 				= ?,    ");
        sql.append("    present 				= ?,");
        sql.append("    present_treat 		= ?,    ");
        sql.append("    history 				= ?,");
        sql.append("    allergy 				= ?,");
        sql.append("    disease 				= ?,");
        sql.append("    suit 				= ?,    ");
        sql.append("    drug 				= ?,    ");

        sql.append("    status 				= ?     ");
        sql.append("                                ");
        sql.append(" WHERE  id 		 = ?            ");

        return JDBCUtil.executeUpdate(sql.toString(),

                register.getName(),
                register.getGender(),
                register.getIdno(),
                register.getBirthday(),
                register.getAge(),
                register.getAddress(),
                register.getRegsitLevelId(),
                register.getDeptId(),
                register.getDoctorId(),
                register.getBook(),
                register.getVisittime(),
                register.getFee(),
                register.getReadme(),
                register.getPresent(),
                register.getPresentTreat(),
                register.getHistory(),
                register.getAllergy(),
                register.getDisease(),
                register.getSuit(),
                register.getDrug(),

                register.getStatus(),
                register.getId()

        );
    }


    /**
     * 逻辑删除，没有真正删除数据
     *
     * @param id
     * @return
     */
    @Override
    public boolean deleteById(Integer id) {

        String sql = " update  register set active = 0 where menu_id  = ? ";

        return JDBCUtil.executeUpdate(sql, id);
    }

    @Override
    public boolean batchDel(String sql, Object... parm) {
        return false;
    }

    @Override
    public boolean insert(Register register) {
        String sql = " INSERT INTO register (   name,   gender,   idno,   birthday,   age,   address,   regsit_level_id,   dept_id,   doctor_id,   book,   visittime,   fee,   readme,   present,   present_treat,   history,   allergy,   disease,   suit,  drug,  status )  VALUES   ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? ) ";
        return JDBCUtil.executeUpdate(sql,
                register.getName(),
                register.getGender(),
                register.getIdno(),
                register.getBirthday(),
                register.getAge(),
                register.getAddress(),
                register.getRegsitLevelId(),
                register.getDeptId(),
                register.getDoctorId(),
                register.getBook(),
                register.getVisittime(),
                register.getFee(),
                register.getReadme(),
                register.getPresent(),
                register.getPresentTreat(),
                register.getHistory(),
                register.getAllergy(),
                register.getDisease(),
                register.getSuit(),
                register.getDrug(),
                register.getStatus()
        );
    }

}
